package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFillFlag;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    public Page<DishVO> findDish(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 新增菜品
     * @param dish
     */
    @AutoFillFlag(OperationType.INSERT)
    public void addDish(Dish dish);


    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    public DishVO findDishById(Long id);


    /**
     * 修改菜品信息
     * @param dish
     * @return
     */
    @AutoFillFlag(OperationType.UPDATE)
    public void changeDish(Dish dish);

    /**
     * 批量删除菜品
     * @param ids
     */
    public void dropDish(List<Long> ids);

    /**
     * 根据分类id查询相关菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id=#{categoryId}")
    public List<Dish> findByCategoryId(Long categoryId);


    public List<Dish> list(Dish dish);


    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
